<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品分类列表')"/>
    <style>
        .treetable-tbody tr[pid^=row_id_]{
            margin-left: 70px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="product-category-form">
                <div class="select-list">
                    <ul>
                        <li>
                            分类名称：<input type="text" name="categoryName" value=""/>
                        </li>
                        <li>
                            分类状态：<select name="isEnable" th:with="type=${@dict.getType('show_status')}">
                            <option value="">全部</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add(0)" shiro:hasPermission="back:productCategory:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="back:productCategory:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-tree-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('back:productCategory:add')}]];
    var editFlag = [[${@permission.hasPermi('back:productCategory:edit')}]];
    var removeFlag = [[${@permission.hasPermi('back:productCategory:remove')}]];
    var datas = [[${@dict.getType('show_status')}]];
    var prefix = ctx + "back/productCategory"

    $(function () {
        var options = {
            code: "id",
            parentCode: "parentId",
            uniqueId: "id",
            height: 600,
            url: prefix + "/searchList",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "商品分类",
            expandAll: false,
            expandFirst: false,
            columns: [{
                field: 'selectItem',
                radio: true
            },
                {
                    field: 'categoryName',
                    title: '商品分类名称',
                    align: "left"
                },
                {
                    field: 'coverUrl',
                    title: '封面图',
                    width:'10%',
                    align: "left",
                    formatter: function (value, row, index) {
                        // var thumbUrl = value + '?imageView2/1/w/64/h/64';
                        return $.common.sprintf("<img class='img-circle img-xs' data-height='%s' data-width='%s' data-target='%s'  style='border-radius: 0;' src='%s' data-src='%s'/>", 500, 'auto', 'self', value, value);
                    }
                },
                {
                    field: 'orderNum',
                    width:'5%',
                    title: '排序',
                    align: "left"
                },
                {
                    field: 'isEnable',
                    title: '状态',
                    align: "left",
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas, item.isEnable);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: "left"
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        if (parseInt(row.id) !== 1) {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);

        // 图片预览事件
        $('#bootstrap-tree-table').off("click").on("click", '.img-circle', function () {
            var src = $(this).attr('src');
            var dataSrc = $(this).attr('data-src');
            if (dataSrc !== undefined) {
                src = dataSrc;
            }
            var target = $(this).data('target');
            var height = $(this).data('height');
            var width = $(this).data('width');
            if ($.common.equals("self", target)) {
                layer.open({
                    title: false,
                    type: 1,
                    closeBtn: true,
                    shadeClose: true,
                    area: ['auto', 'auto'],
                    content: "<img src='" + src + "' height='" + height + "' width='" + width + "'/>"
                });
            } else if ($.common.equals("blank", target)) {
                window.open(src);
            }
        });
    });
</script>
</body>
</html>